package Pages;

import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import Const.IDTouch;
import Core.GLives;
import Core.KEY;
import Core.Slide;
import Core.Touch;

public class EnableSound extends Slide {

	private Image imgCheck = null;
	private Image imgCancel = null;
	
	public void init(){
		try {
			imgCancel = Image.createImage("/bt_cancel.png");
			imgCheck = Image.createImage("/bt_check.png");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void destroy() {
		imgCheck = null;
		imgCancel = null;
	}
	
	public void registerTouch() {
		Touch.addTouchArea(IDTouch.BUY, 0, GLives.ScreenHeight - 40, 70, 40);
		Touch.addTouchArea(IDTouch.HOME, GLives.ScreenWidth-70, GLives.ScreenHeight - 40, 70, 40);
	}

	public void Click(int ID, int x, int y) {
		if(ID==IDTouch.BUY){
			onkeyDown(KEY.LEFT_SOFTKEY);
		}
		else if (ID == IDTouch.HOME){
			onkeyDown(KEY.RIGHT_SOFTKEY);
		}
	}
	
	public void onkeyDown(int keyCode) {
		switch (keyCode) {
		case KEY.LEFT_SOFTKEY:
			sound.setEnable(false);
			changeState(State.MAIN_MENU);
			break;
		case KEY.RIGHT_SOFTKEY:
			sound.setEnable(true);
			changeState(State.MAIN_MENU);
			break;
		}
	}
	
	public void paint(Graphics g) {
		g.setColor(0);
		g.fillRect(0, 0, GLives.ScreenWidth, GLives.ScreenHeight);
		
		drawString(g, "Bạn muốn bật âm thanh?", GLives.ScreenWidth>>1, GLives.ScreenHeight>>1, 2, 0xFFCCFF);
		g.drawImage(imgCancel, 10, GLives.ScreenHeight - 10, Graphics.BOTTOM|Graphics.LEFT);
		g.drawImage(imgCheck, GLives.ScreenWidth - 10, GLives.ScreenHeight - 10, Graphics.BOTTOM|Graphics.RIGHT);
	}
}
